Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

555
Visualizações
aws apigateway import-rest-api returns "Invalid base64" error

I am trying to export and than import AWS Gateway API, following the instructions in https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-migrate-accounts-regions/.

Export is working:

aws apigateway get-export --parameters extensions='apigateway' --rest-api-id MY_REST_API_ID --stage-name Prod --export-type swagger my-api-apigateway.json

Identical files for my API are generated with --parameters extensions='apigateway' and --parameters extensions='integrations'.

But when I try to do the import from the exported file:

aws apigateway import-rest-api --fail-on-warnings --body file://%cd%/my-api-gateway.json

, I am always getting "Invalid base64: " error. Like this:

Invalid base64: "{
  "swagger" : "2.0",
  "info" : {
    "version" : "1.0",
    "title" : "my-stack-name"
  },
  "host" : "MY_REST_API_ID.execute-api.eu-central-1.amazonaws.com",
  "basePath" : "/Prod",
  ...

No documentation and no examples on google say that body should be Base64.

The same JSON seems to work when I import it via UI (Actions -> Import API).

I've also tried to use --cli-input-json:

my-api-apigateway-cli-json.json file (according to aws apigateway import-rest-api --generate-cli-skeleton):

{
  "failOnWarnings": true,
  "parameters": {
    "endpointConfigurationTypes": "REGIONAL"
  },
  "body": {... JSON FROM EXPORT ...}
}

Import command:

aws apigateway import-rest-api --cli-input-json file://./my-api-apigateway-cli-json.json

, but it says

Parameter validation failed:
Invalid type for parameter body, value: {'swagger': '2.0', ...

So, the questions are:

  • Should we encode the json as base64?
  • Why is this error and behaviour not documented (or if yes, then where?)?
  • How to successfully execute import from cli?

Useful links

None of the links say that body response should be Base64

  • https://docs.aws.amazon.com/apigateway/api-reference/link-relation/restapi-import/ -- here body is clearly documented as // raw byte array representing the api definition
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

When importing rest-api into AWS API Gateway using the AWS CLI its not mandatory to encode the json as base64.

I suspect you are using AWS CLI v2 and this issue you are facing, I believe it's as a result of changes introduced in AWS CLI version 2. i.e

AWS CLI version 2 now passes all binary input and binary output parameters as base64-encoded strings by default

Resolution:

You will need add --cli-binary-format raw-in-base64-out so that it tells AWS CLI v2 to revert to the AWS CLI v1 behavior:

aws apigateway import-rest-api --cli-binary-format raw-in-base64-out --body file://my-api-apigateway.json
over 4 years ago · Santiago Trujillo Relatório

0

Using fileb:// instead of file:// worked for me. For example,

aws apigateway import-rest-api --body fileb://my-api.json
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda